package com.zmx.job.admin.core.nodedistribute;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 服务分发节点信息
 * @ClassName: NodeRouteStrategyInfo
 * @Author zhaomxr
 * @Date 2021-12-28 09:38
 */
public class JobRouteStrategyInfo {

    private static Integer lock = 1;
    /**
     * 任务分发的具体实例，key是任务，value是实例地址
     */
    private static Map<String, String> jobInstance;

    public static Map<String, String> getJobInstance() {
        if (jobInstance == null) {
            synchronized (lock) {
                if (jobInstance == null) {
                    jobInstance = new HashMap<String, String>(16);
                }
            }
        }

        return jobInstance;
    }

    /**
     * 取出当前任务最近一次分发服务节点
     * @return
     */
    public static String getJobInstance(String name) {
        if (jobInstance != null) {
            return jobInstance.get(name);
        }
        return "";
    }

    public static void setJobInstance(String job, String node) {
        if (getJobInstance() != null) {
            jobInstance.put(job, node);
        }
    }

}
